/**
 * @Title: SysPermission.java 
 * @Description: TODO
 * @author <a href="mailto:psammead@126.com">Psammead</a>
 * @date 2011-7-14 下午08:14:28 
 * @version 1.0
 * Copyright 2011 by Psammead
 */
package com.psammead.dms.system.sercurity.entity;

import java.io.Serializable;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.psammead.dms.common.core.bo.AbstractBaseBO;

/**
 * @title: 系统权限实体
 * @ClassName: SysPermission
 * @Description: TODO
 * @author <a href="mailto:psammead@126.com">psammead</a>
 * @version 1.0
 * @date 2011-7-14
 */
@Entity(name="SysPermission")
@Table(name="tb_sys_permission")
public class SysPermission extends AbstractBaseBO implements Serializable {

	/**
	 * @Fields serialVersionUID 
	 */
	private static final long serialVersionUID = 1L;
	
	private long id;
	private Set<SysRole> roles;
	private SysResource resource;
	private SysOperation operation;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="permission_id")
	@Override
	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	/**
	 * 获取具有该权限的角色
	 * @Title: getRoles
	 * @Description: 多对多关联SysRole， SysPermission作为被控端
	 * @param 
	 * @return Set<SysRole>
	 * @throws	
	 * @return
	 */
	@ManyToMany(cascade = {CascadeType.PERSIST, CascadeType.MERGE},mappedBy="permissions", fetch = FetchType.LAZY)
	public Set<SysRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<SysRole> roles) {
		this.roles = roles;
	}
	
	@ManyToOne(fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinColumn(name="res_id")
	public SysResource getResource() {
		return resource;
	}

	public void setResource(SysResource resource) {
		this.resource = resource;
	}

	@ManyToOne(fetch = FetchType.LAZY,cascade = {CascadeType.PERSIST, CascadeType.MERGE})
	@JoinColumn(name="oper_id")
	public SysOperation getOperation() {
		return operation;
	}
	
	public void setOperation(SysOperation operation) {
		this.operation = operation;
	}

}
